<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:DentalGUIHelper;assembly=DentalConfig"
  xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
  xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
  xmlns:dentalConverters="clr-namespace:DentalConfig.Converters;assembly=DentalConfig">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../Brushes/MaterialDesign/MaterialDesignTheme.Theme.xaml"/>
    <ResourceDictionary Source="../MaterialControlStyles/MaterialDesignTheme.Button.xaml"/>
  </ResourceDictionary.MergedDictionaries>

  <!-- ========================= -->
  <!-- Converters -->
  <!-- ========================= -->
  <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
  <dentalConverters:ToUpperConverter x:Key="ToUpperConverter"/>
  <dentalConverters:BrushToTransmittantBrushConverter x:Key="BrushToTransmittantBrushConverter"/>

  <!-- ============================== -->
  <!-- ContentAndTextButton Style -->
  <!-- ============================== -->
  <Style x:Key="MaterialDesignContentAndTextButton" TargetType="{x:Type local:ContentAndTextButton}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:ContentAndTextButton}">
          <Grid>
            <wpf:Ripple Focusable="False" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
              <Grid>
                <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
                  <Grid>
                    <Border
                      Background="{TemplateBinding Background}"
                      CornerRadius="2"
                      BorderThickness="{TemplateBinding BorderThickness}"
                      BorderBrush="{TemplateBinding BorderBrush}"
                      x:Name="border"
                      Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"/>
                    <ProgressBar
                      x:Name="ProgressBar"
                      Style="{DynamicResource MaterialDesignLinearProgressBar}"
                      Minimum="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.Minimum)}"
                      Maximum="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.Maximum)}"
                      Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.IndicatorForeground)}"
                      Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.IndicatorBackground)}"
                      Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.Value)}"
                      IsIndeterminate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.IsIndeterminate)}"
                      Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.IsIndicatorVisible), Converter={StaticResource BooleanToVisibilityConverter}}"
                      Height="{TemplateBinding Height}"
                      Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}, Path=ActualWidth}"
                      Opacity="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.Opacity)}"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center"></ProgressBar>
                  </Grid>
                </AdornerDecorator>
                <DockPanel Background="Transparent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                  <!-- Content (= Image) -->
                  <Grid x:Name="grid" Background="#02FFFFFF" DockPanel.Dock="Left" Visibility="{TemplateBinding ShowContent, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <Viewbox Width="{TemplateBinding ContentWidth}" Height="{TemplateBinding ContentHeight}">
                      <Grid>
                        <!-- Content, e.g. Icon -->
                        <Rectangle x:Name="rectangle" Width="{DynamicResource ContentAndTextButtonIconWidth}" Height="{DynamicResource ContentAndTextButtonIconWidth}" Fill="{TemplateBinding Foreground}">
                          <Rectangle.OpacityMask>
                            <VisualBrush>
                              <VisualBrush.Visual>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                              </VisualBrush.Visual>
                            </VisualBrush>
                          </Rectangle.OpacityMask>
                        </Rectangle>
                      </Grid>
                    </Viewbox>
                  </Grid>

                  <!-- Text -->
                  <Grid Name="textContainer" VerticalAlignment="Center" Margin="{TemplateBinding TextMargin}">
                    <Grid.RowDefinitions>
                      <RowDefinition Height="*"/>
                      <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock
                      x:Name="PART_TextBlockMain"
                      Text="{TemplateBinding Text, Converter={StaticResource ToUpperConverter}}"
                      Foreground="{TemplateBinding Foreground}"
                      FontSize="{TemplateBinding FontSize}"
                      FontFamily="{DynamicResource BoldFontFamily}"
                      TextWrapping="WrapWithOverflow"
                      Visibility="{TemplateBinding ShowText, Converter={StaticResource BooleanToVisibilityConverter}}"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center"/>
                    <TextBlock
                      Grid.Row="1"
                      x:Name="PART_TextBlockDescription"
                      Text="{TemplateBinding Description}"
                      Foreground="{DynamicResource ContentAndTextButtonDescriptionTextBrush}"
                      FontSize="{DynamicResource NormalFontSize}"
                      FontFamily="{DynamicResource BoldFontFamily}"
                      Margin="0 2 0 0"
                      TextWrapping="WrapWithOverflow"
                      Visibility="{TemplateBinding ShowDescription, Converter={StaticResource BooleanToVisibilityConverter}}"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center"/>
                  </Grid>
                </DockPanel>
              </Grid>
            </wpf:Ripple>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="TextDock" Value="Right">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Left"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Left">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Right"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Top">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Bottom"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Bottom">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Top"/>
            </Trigger>
            <Trigger Property="ShowText" Value="False">
              <Setter Property="Padding" Value="0"/>
              <Setter Property="TextMargin" Value="0"/>
            </Trigger>
            <Trigger Property="IsFocused" Value="True">
              <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth2"/>
              <Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth2"/>
              <Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
              <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth2"/>
              <Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Opacity" Value="{StaticResource DisabledOpacity}"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignFlatContentAndTextButton" TargetType="{x:Type local:ContentAndTextButton}" BasedOn="{StaticResource MaterialDesignFlatButton}">
    <Setter Property="HorizontalContentAlignment" Value="{Binding RelativeSource={RelativeSource Self}, Path=HorizontalAlignment}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding RelativeSource={RelativeSource Self}, Path=VerticalAlignment}"/>
    <Setter Property="Padding" Value="12, 0, 12, 0"/>
    <Setter Property="TextDock" Value="Right"/>
    <Setter Property="TextMargin" Value="5"/>
    <Setter Property="ContentWidth" Value="Auto"/>
    <Setter Property="ContentHeight" Value="Auto"/>
    <Setter Property="FontSize" Value="18"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:ContentAndTextButton}">
          <Grid>
            <Border Background="Transparent" x:Name="border" CornerRadius="2" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}">
              <wpf:Ripple Focusable="False" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                <Grid>
                  <DockPanel Background="Transparent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                    <!-- Content (= Image) -->
                    <Grid x:Name="grid" Background="#02FFFFFF" DockPanel.Dock="Left" Visibility="{TemplateBinding ShowContent, Converter={StaticResource BooleanToVisibilityConverter}}">
                      <Viewbox Width="{TemplateBinding ContentWidth}" Height="{TemplateBinding ContentHeight}">
                        <Grid>
                          <!-- Content, e.g. Icon -->
                          <Rectangle x:Name="rectangle" Width="{DynamicResource ContentAndTextButtonIconWidth}" Height="{DynamicResource ContentAndTextButtonIconWidth}" Fill="{TemplateBinding Foreground}">
                            <Rectangle.OpacityMask>
                              <VisualBrush>
                                <VisualBrush.Visual>
                                  <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </VisualBrush.Visual>
                              </VisualBrush>
                            </Rectangle.OpacityMask>
                          </Rectangle>
                        </Grid>
                      </Viewbox>
                    </Grid>

                    <!-- Text -->
                    <Grid Name="textContainer" VerticalAlignment="Center" Margin="{TemplateBinding TextMargin}">
                      <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                      </Grid.RowDefinitions>
                      <TextBlock
                        x:Name="PART_TextBlockMain"
                        Text="{TemplateBinding Text, Converter={StaticResource ToUpperConverter}}"
                        Foreground="{TemplateBinding Foreground}"
                        FontSize="{TemplateBinding FontSize}"
                        FontFamily="{DynamicResource BoldFontFamily}"
                        TextWrapping="WrapWithOverflow"
                        Visibility="{TemplateBinding ShowText, Converter={StaticResource BooleanToVisibilityConverter}}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"/>
                      <TextBlock
                        Grid.Row="1"
                        x:Name="PART_TextBlockDescription"
                        Text="{TemplateBinding Description}"
                        Foreground="{DynamicResource ContentAndTextButtonDescriptionTextBrush}"
                        FontSize="{DynamicResource NormalFontSize}"
                        FontFamily="{DynamicResource BoldFontFamily}"
                        Margin="0 2 0 0"
                        TextWrapping="WrapWithOverflow"
                        Visibility="{TemplateBinding ShowDescription, Converter={StaticResource BooleanToVisibilityConverter}}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"/>
                    </Grid>
                  </DockPanel>
                </Grid>
              </wpf:Ripple>
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="TextDock" Value="Right">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Left"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Left"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Left">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Right"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Right"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Top">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Bottom"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Center"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Bottom">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Top"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Center"/>
            </Trigger>
            <Trigger Property="ShowText" Value="False">
              <Setter Property="Padding" Value="0"/>
              <Setter Property="TextMargin" Value="0"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter Property="BorderBrush" TargetName="border" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderBrush}"/>
              <Setter Property="Background" TargetName="border" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Opacity" Value="{StaticResource DisabledOpacity}"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignImageAndTextButton" TargetType="{x:Type local:ImageAndTextButton}" BasedOn="{StaticResource MaterialDesignRaisedButton}">
    <Setter Property="HorizontalContentAlignment" Value="{Binding RelativeSource={RelativeSource Self}, Path=HorizontalAlignment}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding RelativeSource={RelativeSource Self}, Path=VerticalAlignment}"/>
    <Setter Property="Padding" Value="12, 0, 12, 0"/>
    <Setter Property="TextDock" Value="Right"/>
    <Setter Property="TextMargin" Value="5"/>
    <Setter Property="ContentWidth" Value="Auto"/>
    <Setter Property="ContentHeight" Value="Auto"/>
    <Setter Property="FontSize" Value="{DynamicResource BaseButtonFontSize}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:ImageAndTextButton}">
          <Grid>
            <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
              <Grid>
                <Border
                  Background="{TemplateBinding Background}"
                  CornerRadius="2"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  x:Name="border"
                  Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"/>
                <ProgressBar
                  x:Name="ProgressBar"
                  Style="{DynamicResource MaterialDesignLinearProgressBar}"
                  Minimum="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.Minimum)}"
                  Maximum="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.Maximum)}"
                  Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.IndicatorForeground)}"
                  Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.IndicatorBackground)}"
                  Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.Value)}"
                  IsIndeterminate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.IsIndeterminate)}"
                  Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.IsIndicatorVisible), Converter={StaticResource BooleanToVisibilityConverter}}"
                  Height="{TemplateBinding Height}"
                  Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ButtonBase}}, Path=ActualWidth}"
                  Opacity="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ButtonProgressAssist.Opacity)}"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Center"></ProgressBar>
              </Grid>
            </AdornerDecorator>
            <wpf:Ripple Focusable="False" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
              <Grid>
                <DockPanel Background="Transparent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                  <!-- Content (= Image) -->
                  <Grid x:Name="grid" Background="#02FFFFFF" DockPanel.Dock="Left" Visibility="{TemplateBinding ShowContent, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <Viewbox Width="{TemplateBinding ContentWidth}" Height="{TemplateBinding ContentHeight}">
                      <Grid>
                        <!-- Content, e.g. Icon -->
                        <Rectangle x:Name="rectangle" Width="{DynamicResource ContentAndTextButtonIconWidth}" Height="{DynamicResource ContentAndTextButtonIconWidth}" Fill="{TemplateBinding Foreground}">
                          <Rectangle.OpacityMask>
                            <VisualBrush>
                              <VisualBrush.Visual>
                                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                              </VisualBrush.Visual>
                            </VisualBrush>
                          </Rectangle.OpacityMask>
                        </Rectangle>
                      </Grid>
                    </Viewbox>
                  </Grid>

                  <!-- Text -->
                  <Grid Name="textContainer" VerticalAlignment="Center" Margin="{TemplateBinding TextMargin}">
                    <Grid.RowDefinitions>
                      <RowDefinition Height="*"/>
                      <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock
                      x:Name="PART_TextBlockMain"
                      Text="{TemplateBinding Text, Converter={StaticResource ToUpperConverter}}"
                      Foreground="{TemplateBinding Foreground}"
                      FontSize="{TemplateBinding FontSize}"
                      FontFamily="{DynamicResource BoldFontFamily}"
                      TextWrapping="WrapWithOverflow"
                      Visibility="{TemplateBinding ShowText, Converter={StaticResource BooleanToVisibilityConverter}}"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center"/>
                    <TextBlock
                      Grid.Row="1"
                      x:Name="PART_TextBlockDescription"
                      Text="{TemplateBinding Description}"
                      Foreground="{DynamicResource ContentAndTextButtonDescriptionTextBrush}"
                      FontSize="{DynamicResource NormalFontSize}"
                      FontFamily="{DynamicResource BoldFontFamily}"
                      Margin="0 2 0 0"
                      TextWrapping="WrapWithOverflow"
                      Visibility="{TemplateBinding ShowDescription, Converter={StaticResource BooleanToVisibilityConverter}}"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center"/>

                  </Grid>
                </DockPanel>
              </Grid>
            </wpf:Ripple>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="TextDock" Value="Right">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Left"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Left"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Left">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Right"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Right"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Top">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Bottom"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Center"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Bottom">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Top"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Center"/>
            </Trigger>
            <Trigger Property="ShowText" Value="False">
              <Setter Property="Padding" Value="0"/>
              <Setter Property="TextMargin" Value="0"/>
            </Trigger>
            <Trigger Property="IsFocused" Value="True">
              <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth2"/>
              <Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth2"/>
              <Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
              <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth2"/>
              <Setter TargetName="border" Property="wpf:ShadowAssist.Darken" Value="True"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Opacity" Value="{StaticResource DisabledOpacity}"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignAccentImageAndTextButton" TargetType="{x:Type local:ImageAndTextButton}" BasedOn="{StaticResource MaterialDesignImageAndTextButton}">
    <Setter Property="Background" Value="{DynamicResource SecondaryAccentBrush}"/>
    <Setter Property="BorderBrush" Value="{DynamicResource SecondaryAccentBrush}"/>
    <Setter Property="Foreground" Value="{DynamicResource SecondaryAccentForegroundBrush}"/>
  </Style>

  <Style x:Key="MaterialDesignFlatImageAndTextButton" TargetType="{x:Type local:ImageAndTextButton}" BasedOn="{StaticResource MaterialDesignFlatButton}">
    <Setter Property="HorizontalContentAlignment" Value="{Binding RelativeSource={RelativeSource Self}, Path=HorizontalAlignment}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding RelativeSource={RelativeSource Self}, Path=VerticalAlignment}"/>
    <Setter Property="Padding" Value="12, 0, 12, 0"/>
    <Setter Property="TextDock" Value="Right"/>
    <Setter Property="TextMargin" Value="5"/>
    <Setter Property="ContentWidth" Value="Auto"/>
    <Setter Property="ContentHeight" Value="Auto"/>
    <Setter Property="FontSize" Value="18"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:ImageAndTextButton}">
          <Grid>
            <Border Background="Transparent" x:Name="border" CornerRadius="2" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}">
              <wpf:Ripple Focusable="False" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                <Grid>
                  <DockPanel Background="Transparent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                    <!-- Content (= Image) -->
                    <Grid x:Name="grid" Background="#02FFFFFF" DockPanel.Dock="Left" Visibility="{TemplateBinding ShowContent, Converter={StaticResource BooleanToVisibilityConverter}}">
                      <Viewbox Width="{TemplateBinding ContentWidth}" Height="{TemplateBinding ContentHeight}" Stretch="Fill">
                        <Grid>
                          <!-- Content, e.g. Icon -->
                          <Rectangle x:Name="rectangle" Width="{DynamicResource ContentAndTextButtonIconWidth}" Height="{DynamicResource ContentAndTextButtonIconWidth}" Fill="{TemplateBinding Foreground}">
                            <Rectangle.OpacityMask>
                              <VisualBrush>
                                <VisualBrush.Visual>
                                  <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </VisualBrush.Visual>
                              </VisualBrush>
                            </Rectangle.OpacityMask>
                          </Rectangle>
                        </Grid>
                      </Viewbox>
                    </Grid>

                    <!-- Text -->
                    <Grid Name="textContainer" VerticalAlignment="Center" Margin="{TemplateBinding TextMargin}">
                      <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                      </Grid.RowDefinitions>
                      <TextBlock
                        x:Name="PART_TextBlockMain"
                        Text="{TemplateBinding Text, Converter={StaticResource ToUpperConverter}}"
                        Foreground="{TemplateBinding Foreground}"
                        FontSize="{TemplateBinding FontSize}"
                        FontFamily="{DynamicResource BoldFontFamily}"
                        TextWrapping="WrapWithOverflow"
                        Visibility="{TemplateBinding ShowText, Converter={StaticResource BooleanToVisibilityConverter}}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"/>
                      <TextBlock
                        Grid.Row="1"
                        x:Name="PART_TextBlockDescription"
                        Text="{TemplateBinding Description}"
                        Foreground="{DynamicResource ContentAndTextButtonDescriptionTextBrush}"
                        FontSize="{DynamicResource NormalFontSize}"
                        FontFamily="{DynamicResource BoldFontFamily}"
                        Margin="0 2 0 0"
                        TextWrapping="WrapWithOverflow"
                        Visibility="{TemplateBinding ShowDescription, Converter={StaticResource BooleanToVisibilityConverter}}"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"/>

                    </Grid>
                  </DockPanel>
                </Grid>
              </wpf:Ripple>
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <Trigger Property="TextDock" Value="Right">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Left"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Left"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Left">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Right"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Right"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Top">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Bottom"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Center"/>
            </Trigger>
            <Trigger Property="TextDock" Value="Bottom">
              <Setter TargetName="grid" Property="DockPanel.Dock" Value="Top"/>
              <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Center"/>
            </Trigger>
            <Trigger Property="ShowText" Value="False">
              <Setter Property="Padding" Value="0"/>
              <Setter Property="TextMargin" Value="0"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="true">
              <Setter Property="BorderBrush" TargetName="border" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderBrush}"/>
              <Setter Property="Background" TargetName="border" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
              <Setter Property="Opacity" Value="{StaticResource DisabledOpacity}"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type local:ImageAndTextButton}" BasedOn="{StaticResource MaterialDesignImageAndTextButton}"/>
</ResourceDictionary>
